import core.memory;
import std.stdio;
import std.datetime;
import core.thread;

class Testgc
{
    ~this() {writeln("~testgc test");}
    void show() {writeln("show");}
}

void init()
{
    writeln("\t init");
    scope(exit)writeln("\t exit init");
    auto ts = new Testgc();
   
    ts.show();
    //ts.destroy;
    void * hh = cast(void *) ts;
    GC.free(hh);
    return;
}

void init2()
{
    writeln("\t init2");
    scope(exit)writeln("\t exit init2");
    auto i = new int[10];
    GC.free(i.ptr);
}

class MyClass
{
	this(){
		++i;
		gc = new Testgc();
	}
	~this(){
		writeln("free");
		gc.destroy;
		GC.free(cast(void *)gc);
	}
	void show(){
		writeln(i);
	};
private:
	static i = 0;
	Testgc gc;
};

void main()
{
	bool start = true;
	int i = 0;
	while(start){
		auto obj = new MyClass();
		obj.show();
		Thread.sleep(5.msecs);
		//obj.destroy;
            
		//GC.free(cast(void *)obj);
		++i;
		if (i > 2000)
			break;
	}
}
